home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 768 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Static member functions and overloadin
  5. Date: 18 Mar 1996 14:39:10 PST
  6. Organization: Sun Microsystems Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4ikob2$bs1@engnews1.Eng.Sun.COM>
  9. References: <4ikb60$4i@cri.ens-lyon.fr>
  10. Reply-To: clamage@Eng.Sun.COM
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 18 Mar 1996 22:33:06 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMU3mJEy4NqrwXLNJAQGyRwH/XDTLXTRFN34IDvYSoha9zbOkD5iTWNlo
  15.     e43QvPk7Q72IJl1OIZZ+jhaKgYzNERkHpN0RhAAZJFN34SFjc527FA==
  16.     =3Qae
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article 4i@cri.ens-lyon.fr, elesueur@ens-lyon.fr (Emmanuel Lesueur) writes:
  20. >
  21. >Oops... You're right, of course. I swapped the function parameters.
  22. >What about:
  23. >
  24. >>    class A {
  25. >>    public:
  26. >>        void f(char);        #1
  27. >>        static void f(int);    #2
  28. >>    };
  29. >
  30. >>    class B : public A {
  31. >>    };
  32. >
  33. >>    void foo(B& b,char c) {
  34. >>        b.f(c);
  35. >>    }
  36. >
  37. >Is this ambiguous ? As I understand it, the draft paper says yes.
  38. >(gcc says no.)
  39.  
  40. By my reading of the draft, #1 requires a base-class conversion on the
  41. first (implicit) argument and has an exact match on the second (char)
  42. argument. Function #2 has an exact match on the fictional first argument,
  43. and requires a promotion on the second (int) parameter. #2 is preferred
  44. on the first argument and #1 is preferred on the second argument. Thus,
  45. I agree that the call is ambiguous according to the draft standard.
  46.  
  47. The detailed rules for overloading have undergone changes over time, and
  48. I believe under earlier sets of rules f(char) could be unambiguously
  49. selected.
  50.  
  51. I think the rules in the draft make sense in this case, if only because it
  52. is bound to be confusing to have a pair of overloaded functions like these.
  53. I don't think it is obvious that either function is the one intended, so
  54. the ambiguity ensures you specify precisely what you intend. That is,
  55. you give the functions different names, or incompatible parameter lists,
  56. or write the call more explicitly, for example:
  57.     b.f(int(c))
  58.     ((A&)b).f(c)
  59. If you have to write calls like this, I would seriously consider whether
  60. it makes sense to overload the functions.
  61. ---
  62. Steve Clamage, stephen.clamage@eng.sun.com
  63. ---
  64. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  65.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  66.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  67.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  68.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  69. ]
  70.